﻿Partial Public Class InSite
    Inherits System.Web.UI.MasterPage

    Dim ConnectionString As String = ConfigurationManager.AppSettings("ConnectionString").ToString
    Dim objData As New DatabaseClass(ConnectionString)
    Dim objData1 As New DatabaseClass(ConnectionString)
    Dim objFunction As New FunctionClass
    Dim sql As String = ""

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        divMenu.InnerHtml = loadMenu()
        If Not Trim(Session("UserFullname")) = vbNullString Then
            lblFullName.Text = Session("UserFullname").ToString
            If Session("UserImg") = "" Then
                imgAvatar.ImageUrl = "/static/inSite/images/noAvatar.jpg"
            Else
                imgAvatar.ImageUrl = "/static/inSite/images/avatar/" & Session("UserImg").ToString
            End If
        Else
            Response.Redirect("/Inside/xLogin.aspx?redirect=" & Request.Url.PathAndQuery.Replace("?", "|"))
        End If
    End Sub

    ' Hiển thị menu bên trái
    Private Function loadMenu() As String

        'MsgBox("load menu")
        Dim strHTML As New StringBuilder()
        Dim menuCode As String = ""
        Try
            strHTML.AppendLine("<div class='navhead_blank'><span><a href='/Inside/Default.aspx' title=''><img src='/static/inSite/images/icons/dash.png' style='margin-bottom: -7px;margin-right: 5px;'>Bảng thống kê</a></span></div>")

            sql = "spi_getMenu"
            objData.ExeReader(sql)
            Do While objData.dataRead.Read
                menuCode = objData.dataRead("MenuCode").ToString
                strHTML.AppendLine("	<div class='navhead'><span><img src='" & objData.dataRead("MenuIcon").ToString & "' style='margin-bottom: -7px;margin-right: 5px;'>" & objData.dataRead("MenuPageName").ToString & "</span></div>")
                strHTML.AppendLine("		<div class='subnav'>")
                strHTML.AppendLine("			<ul class='submenu'>")

                sql = "spi_getSubMenu " & objFunction.FieldUniCk(menuCode)
                objData1.ExeReader(sql)
                Do While objData1.dataRead.Read
                    strHTML.AppendLine("				<li><a href='" & objData1.dataRead("MenuUrl").ToString & "' title=''><img src='" & objData1.dataRead("MenuIcon").ToString & "' style='margin-bottom: -7px;margin-right: 5px;'>" & objData1.dataRead("MenuPageName").ToString & "</a></li>")
                Loop

                strHTML.AppendLine("			</ul>")
                strHTML.AppendLine("		</div>")
            Loop
            objData.dataRead.Close()
            objData1.dataRead.Close()
            Return strHTML.ToString()
        Catch ex As Exception
            Return ex.Message.ToString
        Finally
            strHTML = Nothing
        End Try
    End Function


    Private Sub btnPrivate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrivate.Click
        Response.Redirect("/Inside/System/User/UserUpdate.aspx?id=" & Session("UserId"))
    End Sub


    Private Sub btnLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogout.Click
        Session.Clear()
        Response.Redirect("/Inside/xLogin.aspx")
    End Sub
End Class